using System;
using System.Data;
using System.Data.OleDb;
using System.Collections;
using System.Configuration;
using PCSComUtils.DataAccess;
using PCSComUtils.PCSExc;
using PCSComUtils.Common;
using System.Runtime.InteropServices;

namespace PCSComSale.Order.DS
{
	[Guid("1092470E-B404-46e2-BE90-B86E2BC47340")]
	public class SO_PackListDetailDS 
	{
		public SO_PackListDetailDS()
		{
		}
		private const string THIS = "PCSComSale.Order.DS.SO_PackListDetailDS";

	
		//**************************************************************************              
		///    <Description>
		///       This method uses to add data to SO_PackListDetail
		///    </Description>
		///    <Inputs>
		///        SO_PackListDetailVO       
		///    </Inputs>
		///    <Outputs>
		///       newly inserted primarkey value
		///    </Outputs>
		///    <Returns>
		///       void
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Tuesday, February 01, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************


		public void Add(object pobjObjectVO)
		{
			const string METHOD_NAME = THIS + ".Add()";
			 
			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS =null;
			try
			{
				SO_PackListDetailVO objObject = (SO_PackListDetailVO) pobjObjectVO;
				string strSql = String.Empty;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand("", oconPCS);
				
				strSql=	"INSERT INTO SO_PackListDetail("
				+ SO_PackListDetailTable.COMMITQUANTITY_FLD + ","
				+ SO_PackListDetailTable.PACKLISTDETAILID_FLD + ","
				+ SO_PackListDetailTable.SALEORDERDETAILID_FLD + ","
				+ SO_PackListDetailTable.PACKLISTMASTERID_FLD + ","
				+ SO_PackListDetailTable.PRODUCTID_FLD + ","
				+ SO_PackListDetailTable.BINID_FLD + ","
				+ SO_PackListDetailTable.LOCATIONID_FLD + ")"
				+ "VALUES(?,?,?,?,?,?,?)";

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListDetailTable.COMMITQUANTITY_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[SO_PackListDetailTable.COMMITQUANTITY_FLD].Value = objObject.CommittedQuantity;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListDetailTable.PACKLISTDETAILID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[SO_PackListDetailTable.PACKLISTDETAILID_FLD].Value = objObject.PackListDetailID;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListDetailTable.SALEORDERDETAILID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[SO_PackListDetailTable.SALEORDERDETAILID_FLD].Value = objObject.SaleOrderDetailId;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListDetailTable.PACKLISTMASTERID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[SO_PackListDetailTable.PACKLISTMASTERID_FLD].Value = objObject.PackListMasterID;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListDetailTable.PRODUCTID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[SO_PackListDetailTable.PRODUCTID_FLD].Value = objObject.ProductID;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListDetailTable.BINID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[SO_PackListDetailTable.BINID_FLD].Value = objObject.BinID;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListDetailTable.LOCATIONID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[SO_PackListDetailTable.LOCATIONID_FLD].Value = objObject.LocationID;


				
				ocmdPCS.CommandText = strSql;
				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	

			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}
	

	

		//**************************************************************************              
		///    <Description>
		///       This method uses to delete data from SO_PackListDetail
		///    </Description>
		///    <Inputs>
		///        ID       
		///    </Inputs>
		///    <Outputs>
		///       void
		///    </Outputs>
		///    <Returns>
		///       
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       09-Dec-2004
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public void Delete(int pintID)
		{
			const string METHOD_NAME = THIS + ".Delete()";
			string strSql = String.Empty;
			strSql=	"DELETE " + SO_PackListDetailTable.TABLE_NAME + " WHERE  " + "MasterLocationID" + "=" + pintID.ToString();
			OleDbConnection oconPCS=null;
			OleDbCommand ocmdPCS =null;
			try
			{
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	
				ocmdPCS = null;

			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}



			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}
        
		//**************************************************************************              
		///    <Description>
		///       This method uses to delete data from SO_PackListDetail
		///    </Description>
		///    <Inputs>
		///        ID       
		///    </Inputs>
		///    <Outputs>
		///       void
		///    </Outputs>
		///    <Returns>
		///       
		///    </Returns>
		///    <Authors>
		///       TuanDm
		///    </Authors>
		///    <History>
		///       09-Dec-2004
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************        
		public void DeleteByCommitInventoryDetail(int pintCommitInventoryDetailID)
		{
			const string METHOD_NAME = THIS + ".DeleteByCommitInventoryDetail()";
			string strSql = String.Empty;
			strSql=	"DELETE " + SO_PackListDetailTable.TABLE_NAME + " WHERE  " + SO_PackListDetailTable.COMMITINVENTORYDETAILID_FLD + "=" + pintCommitInventoryDetailID.ToString();
			OleDbConnection oconPCS=null;
			OleDbCommand ocmdPCS =null;
			try
			{
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	
				ocmdPCS = null;

			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}



			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}

		//**************************************************************************              
		///    <Description>
		///       This method uses to delete data from SO_PackListDetail
		///    </Description>
		///    <Inputs>
		///        ID       
		///    </Inputs>
		///    <Outputs>
		///       void
		///    </Outputs>
		///    <Returns>
		///       
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       09-Dec-2004
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public void DeleteDetailForMaster(int pintMasterID)
		{
			const string METHOD_NAME = THIS + ".Delete()";
			string strSql = String.Empty;
			strSql=	"DELETE " + SO_PackListDetailTable.TABLE_NAME + " WHERE  " + SO_PackListDetailTable.PACKLISTMASTERID_FLD + "=" + pintMasterID.ToString();
			OleDbConnection oconPCS=null;
			OleDbCommand ocmdPCS =null;
			try
			{
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	
				ocmdPCS = null;

			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}
			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}

		//**************************************************************************              
		///    <Description>
		///       This method uses to get data from SO_PackListDetail
		///    </Description>
		///    <Inputs>
		///        ID       
		///    </Inputs>
		///    <Outputs>
		///       SO_PackListDetailVO
		///    </Outputs>
		///    <Returns>
		///       SO_PackListDetailVO
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Tuesday, February 01, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************

		public object GetObjectVO(int pintID)
		{
			const string METHOD_NAME = THIS + ".GetObjectVO()";
			DataSet dstPCS = new DataSet();
			
			OleDbDataReader odrPCS = null;
			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = String.Empty;
				strSql=	"SELECT "
				+ SO_PackListDetailTable.MASTERLOCATIONID_FLD + ","
				+ SO_PackListDetailTable.COMMITQUANTITY_FLD + ","
				+ SO_PackListDetailTable.PACKLISTDETAILID_FLD + ","
				+ SO_PackListDetailTable.SALEORDERDETAILID_FLD + ","
				+ SO_PackListDetailTable.PACKLISTMASTERID_FLD + ","
				+ SO_PackListDetailTable.PRODUCTID_FLD + ","
				+ SO_PackListDetailTable.BINID_FLD + ","
				+ SO_PackListDetailTable.LOCATIONID_FLD + ","
				+ SO_PackListDetailTable.COMMITINVENTORYDETAILID_FLD
				+ " FROM " + SO_PackListDetailTable.TABLE_NAME
				+" WHERE " + SO_PackListDetailTable.MASTERLOCATIONID_FLD + "=" + pintID;

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Connection.Open();
				odrPCS = ocmdPCS.ExecuteReader();

				SO_PackListDetailVO objObject = new SO_PackListDetailVO();

				while (odrPCS.Read())
				{ 
					objObject.MasterLocationID = int.Parse(odrPCS[SO_PackListDetailTable.MASTERLOCATIONID_FLD].ToString().Trim());
					objObject.CommittedQuantity = Decimal.Parse(odrPCS[SO_PackListDetailTable.COMMITQUANTITY_FLD].ToString().Trim());
					objObject.PackListDetailID = int.Parse(odrPCS[SO_PackListDetailTable.PACKLISTDETAILID_FLD].ToString().Trim());
					objObject.SaleOrderDetailId = int.Parse(odrPCS[SO_PackListDetailTable.SALEORDERDETAILID_FLD].ToString().Trim());
					objObject.PackListMasterID = int.Parse(odrPCS[SO_PackListDetailTable.PACKLISTMASTERID_FLD].ToString().Trim());
					objObject.ProductID = int.Parse(odrPCS[SO_PackListDetailTable.PRODUCTID_FLD].ToString().Trim());
					objObject.BinID = int.Parse(odrPCS[SO_PackListDetailTable.BINID_FLD].ToString().Trim());
					objObject.LocationID = int.Parse(odrPCS[SO_PackListDetailTable.LOCATIONID_FLD].ToString().Trim());
					objObject.CommitInventoryDetailID = int.Parse(odrPCS[SO_PackListDetailTable.COMMITINVENTORYDETAILID_FLD].ToString().Trim());
				}		
				return objObject;					
			}
			catch(OleDbException ex)
			{			
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}			

			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}


		//**************************************************************************              
		///    <Description>
		///       This method uses to update data to SO_PackListDetail
		///    </Description>
		///    <Inputs>
		///       SO_PackListDetailVO       
		///    </Inputs>
		///    <Outputs>
		///       
		///    </Outputs>
		///    <Returns>
		///       
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       09-Dec-2004
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		
	
		public void Update(object pobjObjecVO)
		{
			const string METHOD_NAME = THIS + ".Update()";

			SO_PackListDetailVO objObject = (SO_PackListDetailVO) pobjObjecVO;
			
			//prepare value for parameters
			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = String.Empty;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				strSql=	"UPDATE SO_PackListDetail SET "
				+ SO_PackListDetailTable.COMMITQUANTITY_FLD + "=   ?" + ","
				+ SO_PackListDetailTable.PACKLISTDETAILID_FLD + "=   ?" + ","
				+ SO_PackListDetailTable.SALEORDERDETAILID_FLD + "=   ?" + ","
				+ SO_PackListDetailTable.PACKLISTMASTERID_FLD + "=   ?" + ","
				+ SO_PackListDetailTable.PRODUCTID_FLD + "=   ?" + ","
				+ SO_PackListDetailTable.BINID_FLD + "=   ?" + ","
				+ SO_PackListDetailTable.LOCATIONID_FLD + "=  ?"
				+" WHERE " + SO_PackListDetailTable.MASTERLOCATIONID_FLD + "= ?";

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListDetailTable.COMMITQUANTITY_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[SO_PackListDetailTable.COMMITQUANTITY_FLD].Value = objObject.CommittedQuantity;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListDetailTable.PACKLISTDETAILID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[SO_PackListDetailTable.PACKLISTDETAILID_FLD].Value = objObject.PackListDetailID;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListDetailTable.SALEORDERDETAILID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[SO_PackListDetailTable.SALEORDERDETAILID_FLD].Value = objObject.SaleOrderDetailId;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListDetailTable.PACKLISTMASTERID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[SO_PackListDetailTable.PACKLISTMASTERID_FLD].Value = objObject.PackListMasterID;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListDetailTable.PRODUCTID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[SO_PackListDetailTable.PRODUCTID_FLD].Value = objObject.ProductID;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListDetailTable.BINID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[SO_PackListDetailTable.BINID_FLD].Value = objObject.BinID;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListDetailTable.LOCATIONID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[SO_PackListDetailTable.LOCATIONID_FLD].Value = objObject.LocationID;

				ocmdPCS.Parameters.Add(new OleDbParameter(SO_PackListDetailTable.MASTERLOCATIONID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[SO_PackListDetailTable.MASTERLOCATIONID_FLD].Value = objObject.MasterLocationID;


				ocmdPCS.CommandText = strSql;
				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	
			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}

		}


		//**************************************************************************              
		///    <Description>
		///       This method uses to get all data from SO_PackListDetail
		///    </Description>
		///    <Inputs>
		///               
		///    </Inputs>
		///    <Outputs>
		///       DataSet
		///    </Outputs>
		///    <Returns>
		///       DataSet
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Tuesday, February 01, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************

		public DataSet List()
		{
			const string METHOD_NAME = THIS + ".List()";
			DataSet dstPCS = new DataSet();
			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = String.Empty;
				
				strSql=	"SELECT "
				+ SO_PackListDetailTable.MASTERLOCATIONID_FLD + ","
				+ SO_PackListDetailTable.COMMITQUANTITY_FLD + ","
				+ SO_PackListDetailTable.PACKLISTDETAILID_FLD + ","
				+ SO_PackListDetailTable.SALEORDERDETAILID_FLD + ","
				+ SO_PackListDetailTable.PACKLISTMASTERID_FLD + ","
				+ SO_PackListDetailTable.PRODUCTID_FLD + ","
				+ SO_PackListDetailTable.BINID_FLD + ","
				+ SO_PackListDetailTable.LOCATIONID_FLD
					+ " FROM " + SO_PackListDetailTable.TABLE_NAME;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				ocmdPCS.Connection.Open();
				
				OleDbDataAdapter odadPCS = new OleDbDataAdapter(ocmdPCS);
				odadPCS.Fill(dstPCS,SO_PackListDetailTable.TABLE_NAME);

				return dstPCS;
			}
			catch(OleDbException ex)
			{
   				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}			
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}

		//**************************************************************************              
		///    <Description>
		///       This method uses to get all pack list item satisfying a condition
		///    </Description>
		///    <Inputs>
		///        string pstrCondition       
		///    </Inputs>
		///    <Outputs>
		///    </Outputs>
		///    <Returns>
		///       DataSet
		///    </Returns>
		///    <Authors>
		///       TuanDm
		///    </Authors>
		///    <History>
		///       Friday, February 04, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public DataSet ListPackListDetailByCondition(string pstrCondition)
		{
			const string METHOD_NAME = THIS + ".ListByCondition()";
			DataSet dstPCS = new DataSet();
			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = String.Empty;
				
				strSql=	"SELECT "
					+ SO_PackListDetailTable.COMMITQUANTITY_FLD + ","
					+ "A." + SO_PackListDetailTable.LOCATIONID_FLD + ","
					+ "A." + SO_PackListDetailTable.BINID_FLD + ","
					+ "A." + SO_PackListDetailTable.PRODUCTID_FLD + ","
					+ "B." + MST_LocationTable.NAME_FLD + " as LocationName,"
					+ "C." + MST_BINTable.NAME_FLD + " as BinName,"
					+ ITM_ProductTable.DESCRIPTION_FLD + " as ProductName,"
					+ "A." + SO_PackListDetailTable.MASTERLOCATIONID_FLD + ","
					+ SO_PackListDetailTable.SALEORDERDETAILID_FLD + ","
					+ SO_PackListDetailTable.PACKLISTMASTERID_FLD + ","
					+ SO_PackListDetailTable.PACKLISTDETAILID_FLD
					+ " FROM " + SO_PackListDetailTable.TABLE_NAME + " A inner join " + MST_LocationTable.TABLE_NAME + " B on A.LocationID = B.LocationID "
					+ " inner join " + MST_BINTable.TABLE_NAME + " C on A.BinID = C.BinID "
					+ " inner join " + ITM_ProductTable.TABLE_NAME + " D on A.ProductID = D.ProductID"
					+ " WHERE " + pstrCondition;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				ocmdPCS.Connection.Open();
				
				OleDbDataAdapter odadPCS = new OleDbDataAdapter(ocmdPCS);
				odadPCS.Fill(dstPCS,SO_PackListDetailTable.TABLE_NAME);

				return dstPCS;
			}
			catch(OleDbException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}			
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}
			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}

		public DataSet ListPackDetailByPackMaster(int pintPackListMasterID)
		{
			const string METHOD_NAME = THIS + ".ListByCondition()";
			DataSet dstPCS = new DataSet();
			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = String.Empty;
				
				strSql=	"SELECT "
					+ "PLDetail." + SO_PackListDetailTable.COMMITINVENTORYDETAILID_FLD + ","
					+ "PLDetail." + SO_PackListDetailTable.LOCATIONID_FLD + ","
					+ "PLDetail." + SO_PackListDetailTable.BINID_FLD + ","
					+ "PLDetail." + SO_PackListDetailTable.PRODUCTID_FLD + ","
					+ "SOMaster." + SO_SaleOrderMasterTable.CODE_FLD + " as " + SO_SaleOrderMasterTable.TABLE_NAME + SO_SaleOrderMasterTable.CODE_FLD + ","
					+ "SODel." + SO_SaleOrderDetailTable.SALEORDERLINE_FLD + ","
					+ "PRO." + ITM_ProductTable.CODE_FLD + ","
					+ "PRO." + ITM_ProductTable.DESCRIPTION_FLD + " as ProductName, "
					+ "PRO." + ITM_ProductTable.REVISION_FLD + " as " + ITM_ProductTable.REVISION_FLD + ","
					+ "(Select " + MST_UnitOfMeasureTable.CODE_FLD + " From " + MST_UnitOfMeasureTable.TABLE_NAME + " Where " + MST_UnitOfMeasureTable.UNITOFMEASUREID_FLD + " = SODel." + SO_SaleOrderDetailTable.STOCKUMID_FLD + ") as " + MST_UnitOfMeasureTable.TABLE_NAME + MST_UnitOfMeasureTable.CODE_FLD + ","
					+ "PLDetail." + SO_PackListDetailTable.COMMITQUANTITY_FLD + ","
					+ "(Select Name From MST_Location Where LocationID = PLDetail.LocationID) as LocationName, PLDetail.MASTERLOCATIONID,"
					+ "(Select Name From MST_Bin Where BinID = PLDetail.BinID) as BinName,"
					+ "(Select " + MST_PartyTable.NAME_FLD + " From " + MST_PartyTable.TABLE_NAME + " Where " + MST_PartyTable.PARTYID_FLD + " = SOMaster." + SO_SaleOrderMasterTable.PARTYID_FLD + ") as " + MST_PartyTable.TABLE_NAME + MST_PartyTable.NAME_FLD + ","
					+ "null as Lot, null as Serial,"
					+ "SODel." + SO_PackListDetailTable.SALEORDERDETAILID_FLD + ","
					+ SO_PackListDetailTable.PACKLISTMASTERID_FLD + ","
					+ SO_PackListDetailTable.PACKLISTDETAILID_FLD
					+ " FROM " + SO_PackListDetailTable.TABLE_NAME + " PLDetail "
					+ " inner join " + SO_SaleOrderDetailTable.TABLE_NAME + " SODel on SODel." + SO_SaleOrderDetailTable.SALEORDERDETAILID_FLD + "= PLDetail." + SO_PackListDetailTable.SALEORDERDETAILID_FLD
					+ " inner join " + SO_SaleOrderMasterTable.TABLE_NAME + " SOMaster on SOMaster." + SO_SaleOrderMasterTable.SALEORDERMASTERID_FLD + "=SODel." + SO_SaleOrderDetailTable.SALEORDERMASTERID_FLD
					+ " inner join " + ITM_ProductTable.TABLE_NAME + " PRO on PRO." + ITM_ProductTable.PRODUCTID_FLD + "= PLDetail." + SO_PackListDetailTable.PRODUCTID_FLD
					+ " WHERE PackListMasterID = " + pintPackListMasterID;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				ocmdPCS.Connection.Open();
				
				OleDbDataAdapter odadPCS = new OleDbDataAdapter(ocmdPCS);
				odadPCS.Fill(dstPCS,SO_PackListDetailTable.TABLE_NAME);

				return dstPCS;
			}
			catch(OleDbException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}			
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}
			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}

		//**************************************************************************              
		///    <Description>
		///       This method uses to update a DataSet
		///    </Description>
		///    <Inputs>
		///        DataSet       
		///    </Inputs>
		///    <Outputs>
		///       
		///    </Outputs>
		///    <Returns>
		///       
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Tuesday, February 01, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public void UpdateDataSet(DataSet pData)
		{
			const string METHOD_NAME = THIS + ".UpdateDataSet()";
			string strSql;
			OleDbConnection oconPCS =null;
			OleDbCommandBuilder odcbPCS ;
			OleDbDataAdapter odadPCS = new OleDbDataAdapter();

			try
			{
				strSql=	"SELECT "
					+ SO_PackListDetailTable.PACKLISTDETAILID_FLD + ","
					+ SO_PackListDetailTable.MASTERLOCATIONID_FLD + ","
					+ SO_PackListDetailTable.COMMITQUANTITY_FLD + ","
					+ SO_PackListDetailTable.PRODUCTID_FLD + ","
					+ SO_PackListDetailTable.BINID_FLD + ","
					+ SO_PackListDetailTable.LOCATIONID_FLD + ","
					+ SO_PackListDetailTable.SALEORDERDETAILID_FLD + ","
					+ SO_PackListDetailTable.PACKLISTMASTERID_FLD + ","
					+ SO_PackListDetailTable.COMMITINVENTORYDETAILID_FLD
				+ "  FROM " + SO_PackListDetailTable.TABLE_NAME;

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				odadPCS.SelectCommand = new OleDbCommand(strSql, oconPCS);
				odcbPCS = new OleDbCommandBuilder(odadPCS);
				pData.EnforceConstraints = false;
				
				odadPCS.Update(pData, SO_PackListDetailTable.TABLE_NAME);

				pData.AcceptChanges();
			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
				{

					throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);				
				}
				
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}


		//**************************************************************************              
		///    <Description>
		///			Delete PackListDetail by CommitInventoryDetailID
		///    </Description>
		///    <Inputs>
		///    </Inputs>
		///    <Outputs>
		///    </Outputs>
		///    <Returns>
		///       void
		///    </Returns>
		///    <Authors>
		///       TuanDm
		///    </Authors>
		///    <History>
		///       Monday, Mar 07, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public void DetelePackListDetailByCommitDetail(int pintPackListDetailID)
		{
			const string METHOD_NAME = THIS + ".Delete()";
			string strSql = String.Empty;
			strSql=	"Delete SO_PackListDetail " +
					"Where PackListDetailID = ( " +
					"Select PackListDetailID " +
					"From SO_PackListDetail A inner join SO_DeliverySchedule B on A.SaleOrderDetailID = B.SaleOrderDetailID " +
					"Inner join SO_CommitInventoryDetail C on B.DeliveryScheduleID = C.DeliveryScheduleID " +
					"Where C.CommitInventoryDetailID = " + pintPackListDetailID.ToString() + ")";
			OleDbConnection oconPCS=null;
			OleDbCommand ocmdPCS =null;
			try
			{
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	
				ocmdPCS = null;

			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}
	}
}
